<?php
session_start();
?>
<?php
include "init.php";
$title = $_POST["title"];
$text = $_POST["text"];
$date_add = $_POST["date_add"];

$uploadfile = "Upload/" . $_FILES['uploadfile']['name'];
move_uploaded_file($_FILES['uploadfile']['tmp_name'], $uploadfile);
if (isset($_POST["id"]) && !empty($_POST["id"])) {
    $result = mysql_query("update date set title='" . $title . "', text ='" . $text . "',date_add='" . date("Y-m-d H:i:s") . "' where id=" . $_POST['id'] . "");
} else {
    $result = mysql_query("INSERT INTO date (title, text, date_add, USER_ID) VALUES ('$title', '$text', '" . date("Y-m-d H:i:s") . "', '" . $_SESSION["user"]["id"] . "') ");
}

if ($result == 'true') {
    echo "OK";
} else {
    echo "no no";
}
?>
<script type="text/javascript">location.href = 'output.php';</script>
